<template>
    <section class="jumbotron">
        <h3 class="jumbotron-heading">Search Github Users</h3>
        <div>
            <input type="text" placeholder="enter the name you search" v-model.trim="textVal" @keydown.enter="SearchUsers"/>&nbsp;<button @click="SearchUsers">Search</button>
        </div>
    </section>
</template>

<script>
import axios from 'axios';
export default {
    data(){
        return {
            textVal:'',
        }
    },
    methods: {
        SearchUsers(){
            if(!this.textVal) return;
            console.log("请求中...");
            this.$bus.$emit('getUsers',{isImg:true,isH1:false});
            axios.get(`https://api.github.com/search/users?q=${this.textVal}`)
            .then(res => {
                console.log("请求用户列表成功了");
                // 请求成功后更新List的数据
                this.$bus.$emit('getUsers',{users:res.data.items,isImg:false,});
            })
            .catch(err => {
                // 请求失败后更新List的数据
                console.log("请求用户列表失败了");
                this.$bus.$emit('getUsers',{isImg:false,errMsg:err.message});
            })
        }
    },
}
</script>

<style>

</style>